<template>
	<view class="box">
		<view class="fontweight">我的账户</view>
		<view class="head">
			<u-row customStyle="margin-bottom: 10px">
			    <u-col span="6">
			        <view class="demo-layout ">
						<span>账户余额</span>
					</view>
			    </u-col>
			    <u-col span="6">
			        <view class="demo-layout bg-purple"></view>
			    </u-col>
			</u-row>
			<u-row customStyle="margin-bottom: 10px">
			    <u-col span="6">
			        <view class="bg-purple-light fontweight">
						{{(noWithdrawal/100).toFixed(2)}}元
					</view>
			    </u-col>
			    <u-col span="4">
			        <view class="demo-layout bg-purple"></view>
			    </u-col>
				<u-col span="2">
				    <view class="demo-layout bg-purple">
						<u-button type="success" text="提现" size="mini" @click="showWithdrawal=true,form.withdrawalMoney=(noWithdrawal/100).toFixed(2)"></u-button>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="content2">
			<u-row customStyle="margin-bottom: 10px">
			    <u-col span="6" @click="navigateTo('/pagesB/my/accountDetails')">
			        <view class="demo-layout " >
			        	<view >
							<u-icon name="red-packet" color="#00ac4e" size="30"></u-icon>
						</view>
					</view>
					<view>
						<span>账户明细</span>
					</view>
			    </u-col>
			   <!-- <u-col span="4" @click="utils.developing">
			        <view class="demo-layout " >
			        	<view >
			        		<u-icon name="red-packet" color="#00ac4e" size="30"></u-icon>
			        	</view>
			        </view>
			        <view>
			        	<span>接单明细</span>
			        </view>
			    </u-col> -->
				<u-col span="6" @click="navigateTo('/pagesB/my/withdrawalRecords')">
				    <view class="demo-layout " >
				    	<view >
				    		<u-icon name="red-packet" color="#00ac4e" size="30"></u-icon>
				    	</view>
				    </view>
				    <view>
				    	<span>提现记录</span>
				    </view>
				</u-col>
				<!-- <u-col span="4">
				    <view class="demo-layout " >
				    	<u-icon name="../../static/Icon/6.png" color="#2979ff" size="30"></u-icon>
				    </view>
					<view>
						<span>银行卡</span>
					</view>
				</u-col> -->
				
			</u-row>
			<u-line color="#c9c8cc"></u-line>
		</view>
		<view>
			<view style="margin-left: 20rpx;margin-bottom: 10px;" class="fontweight">
				<view class="" v-if="todaylist.length==0">
					今日无入账
					<u-empty      text="今日无入账明细"    icon="https://cdn.uviewui.com/uview/empty/history.png">
					</u-empty>
				</view>
				<view v-else>
					今日完成单
				</view>
			</view>
			<view   class="content3" v-for="(item, index) in todaylist" @click="navigateTodetails(item.orderNo)">
				<u-row customStyle="margin-bottom:0px">
				    <u-col span="6">
				       <view class="demo-left" >
				       	完:<span >{{item.completeTime}} </span>
				       </view>
				    </u-col>
					<u-col span="3">
						<view >
							<view class="typeName">
								{{item.serveName}}
							</view>
						</view>
					</u-col>
				    <u-col span="3">
				        <view class="demo-right" >
				        	<view v-if="item.orderStatus==0&&item.finalPrice!=0" style="color: #00ac4e;">
								待入账<span> {{(item.totalPrice/100).toFixed(2)}}元</span>
							</view>
							<view v-else>
								入账<span> {{(item.totalPrice/100).toFixed(2)}}元</span>
							</view>
							
				        </view>
						<uview-ui>
							<u-divider></u-divider>
							<span></span>
						</uview-ui>
				    </u-col>
				</u-row>
				<u-steps  direction="column" dot activeColor="#ffd02b" inactiveColor="#00ac4e" style="margin-top: 10px;">
					<u-steps-item :title="item.userAddress" :desc="item.address">
					</u-steps-item>
				</u-steps>  
			
			</view>	
			<!-- <view class="content3" v-for="(item, index) in todaylist" @click="navigateTodetails(item.orderNo)">
				<u-row customStyle="margin-bottom: 10px">
				    <u-col span="8">
				        <view class="demo-layout bg-purple-light">
							<span>{{utils.dateFormat(item.createTime)}}</span>
						</view>
						<view>
							<h4>{{item.serveName}}</h4>
						</view>
				    </u-col>
				    <u-col span="4">
				        <view class="right" >
				        	<span>入账</span>
				        </view>
				        <view class="right" >
							 <h4>+{{(item.price/100).toFixed(2)}}</h4>
				        </view>
				    </u-col>
					
				</u-row>
			</view> -->
		</view>
		<view class="content4">
			<u-popup :show="showWithdrawal"  :round="10"  mode="center"   @close="show=false">
				<view class="Withdrawal">
					<u--form :rules="rules"  :model="form" ref="uform" labelPosition="left" labelWidth="80">
						
						<u-form-item label="提现金额:" prop="withdrawalMoney"	 borderBottom ref="item1">
							<u--input type="digit" auto-focus	v-model="form.withdrawalMoney"	border="none">
									<template slot="suffix">
										
										<u-button
											type="warning"
											text="全部"
											color="#000000"
											size="mini"
											@click="wholeMoney"
										></u-button>
									</template>
							</u--input>
						</u-form-item>
						<u-form-item label="备注:"	 borderBottom ref="item1">
							<u--input	v-model="form.remark"	border="none"> </u--input>
						</u-form-item>
						<u-row customStyle="margin-top: 30px"  gutter="40">
						    <u-col span="6">
						         <u-button  size="normal" @click="showWithdrawal=false" >取消</u-button>
						    </u-col>
							<u-col span="6" >
							    <u-button   size="normal"    type="success" @click="submit" :disabled="submitBtn">提交</u-button>
							</u-col>
						    
						</u-row>
						
					</u--form>
				</view>
			</u-popup>
		</view>
		
	</view>
</template>

<script>
	import {
	    mapState 
	} from 'vuex';
	export default {
		data() {
			return {
				noWithdrawal:0,//待提现金额
				showWithdrawal:false,
				submitBtn:false,
				pageVO:{
					pageNo: 1,
					pageSize: 99,
					technicianId:"", 
					//createTime:["2023-10-09 00:00:00","2023-10-10 00:00:00"],
					//appcreateTime:["2023-10-09 00:00:00"],
					/* start:"2023-10-09 00:00:00",
					end:"2023-10-10 00:00:00",
					type:1, */
					receiveStatus:4,//技师接单状态（1未接单，2已接单，3服务中，4已完成，5拒绝接单，6取消）
					completeTime:"",
					sort:"descCompleteTime",//排序
				},
				todaylist:[],
				form:{
					withdrawalMoney:"",//提现金额
					remark:"",//备注
					technicianId:"", 
				},
				rules: {
					'withdrawalMoney': [
						{min:0.01,type: 'float',required: true,message: '请输入金额',trigger: ['blur', 'change']},
						{pattern: /^(\d?)+(\.\d{0,2})?$/,message: '请输入合法金额',trigger: ['blur', 'change']}
					]
				},
			}
		},
		computed: {
			//获取是否登录
			...mapState(['hasLogin','userInfo']) 
		},
		onReady() {
			this.$refs.uform.setRules(this.rules)
		},
		mounted() {
			this.showPage(true)
			let tody=new Date();
			let tomday=new Date()
			//this.pageVO.createTime[0]=uni.$u.timeFormat(new Date(), 'yyyy-mm-dd')+" 00:00:00";
			//this.pageVO.createTime[1]=uni.$u.timeFormat(tomday.setDate(tody.getDate()+1), 'yyyy-mm-dd')+" 00:00:00";
			
			this.pageVO.start=uni.$u.timeFormat(new Date(), 'yyyy-mm-dd')+" 00:00:00";
			this.pageVO.end=uni.$u.timeFormat(tomday.setDate(tody.getDate()+1), 'yyyy-mm-dd')+" 00:00:00";
			
			this.showMoneyPage()
			this.form.withdrawalMoney=this.noWithdrawal
		},
		methods: {
			//查询账户余额
			showPage(type){
				this.request.getRequest(this.http.httpsLian.getTechnician,{id:this.userInfo.id}, type)
				.then(res => { 
					if(res.code!=0 )return 
					this.noWithdrawal=res.data.noWithdrawal
				}).catch(res => { 
					uni.$u.toast("网络异常13")
				})
			},
			//查询今日入账记录
			showMoneyPage(){ 
				let s=["0","1"]
				/* this.pageVO.technicianId=this.userInfo.id
				this.request.getRequest(this.http.httpsLian.getTechnicianMoneyRecord3,this.pageVO, true)
				.then(res => { 
					if(res.code!=0 )return 
					this.todaylist=res.data.list
				}).catch(res => {
					uni.$u.toast(res)
				}) */
				this.pageVO.completeTime=uni.$u.timeFormat(new Date(), 'yyyy-mm-dd')
				this.request.getRequest(this.http.httpsLian.orderDispatchRecord,this.pageVO, false)
				.then(res => { 
					if(res.code!=0 )return ;
					this.todaylist=res.data.list
					
				}).catch(res => {
					uni.$u.toast(res)
				})
			},
			submit(){
				this.submitBtn=true
				this.$refs.uform.validate().then(res => {
					this.submitBtn=false
					let datas={
						withdrawalMoney:this.form.withdrawalMoney*100,//提现金额
						remark:this.form.remark,//备注
						technicianId:this.userInfo.id, 
					}
					if(this.form.withdrawalMoney==0)return uni.$u.toast('校验失败') ;
					this.post(datas)
				}).catch(errors => {
					this.submitBtn=false
					//uni.$u.toast('校验失败')
				})
			},
			post(datas){
				this.submitBtn=true
				this.request.postRequest(this.http.httpsLian.TechnicianWithdrawalApplyWithdrawal,datas,true)
				.then(res => { 
					console.log("提现返回:"+JSON.stringify(res))
					this.submitBtn=false
					this.showWithdrawal=false
					let iconMsg;
					if(res.code==0)iconMsg=true;
					if(res.code!=0)iconMsg=false;
					uni.showToast({
						title:iconMsg?"提交成功":'提交失败',
						icon:iconMsg?"success":"error",
						duration: 1800
					})
					this.showPage(false)
				}).catch(res => {
					uni.$u.toast(res)
				})
			},
			//全部金额
			wholeMoney(){
				this.form.withdrawalMoney=(this.noWithdrawal/100).toFixed(2)
			},
			navigateTodetails(orderNo){
				
				uni.navigateTo({
				   url: "/pagesB/serviceList/details?params="+encodeURIComponent(JSON.stringify({orderNo:orderNo}))
				});
			},
			navigateTo(url){
				uni.navigateTo({
				   url: url
				});
			},
		}
	}
</script>
<style lang="scss" scoped>
.box{
	margin-top: 10rpx;
	padding: 0px 10px;
}
.head{
	background-color: $Main-yellow-color;
	padding: 10px 10px;
	margin-top: 10px;
	border-radius: 4px;
	/deep/.u-button--success{
		    color: #ffffff;
		    background-color: $Main-green-color;
		    border-color: $Main-green-color;
		   
		}
	.demo-layout{
		font-size: 12px;
	}	
	
}

.content2{
	//background-color: red;
	padding-bottom: 20rpx;
	margin-bottom: 20rpx;
	border-radius: 15rpx;
	.demo-layout {
		    border-radius: 4px;
			margin: 0px auto;
			margin-bottom: 10rpx;
			margin-top: 20rpx;
		view{
			//background-color: red;
			width: 62rpx;
			margin: 0px auto;
		}	
	}
	view{
		font-size: 11px;
		text-align: center;
		
	}	
	
}
.content3{
	background-color: white;
	padding: 8px ;
	margin-bottom: 10px;
	border-radius: 4px;
	.demo-right {
		text-align: right;
		span{
			color: red;
		}
		font-size: 22rpx !important;
	}
	.demo-left{
		color: $uni-text-color-placeholder;
	}
	.demo-left,.demo-right{
		font-size: 12px;
	}
	

}
.content3{
	/* padding-bottom: 20rpx;
	border-radius: 5rpx;
	margin-top: 15rpx;
	padding-right: 20px;
	background-color: #fff;
	.demo-layout {
		    border-radius: 4px;
			//margin: 0px auto;
			margin-bottom: 10rpx;
			margin-top: 20rpx;
			
		}
	view{
		margin-left: 10px;
		//text-align: center;
	}		
	span{
		font-size: 12px;
		color: $font-color-secondary;
	}
	.right{
		text-align: right
		
	} */
}
.fontweight{
	font-weight: 550;
}

.Withdrawal{
	padding: 15px;
}
</style>
